package com.heer.gymnasium.module.map.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.heer.gymnasium.R;
import com.zhihuiyun.library.utils.L;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yan
 * on 2018/3/8
 */

public class LocationAdapter extends BaseAdapter {
    private List<PoiItem> data;
    private Context context;

    public LocationAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<PoiItem> data) {
        this.data.clear();
        if (data != null) {
            this.data.addAll(data);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_location, null);
            viewHolder = new ViewHolder();
            viewHolder.areaTextView = (TextView) view.findViewById(R.id.item_location_eare_tv);
            viewHolder.detailTextView = (TextView) view.findViewById(R.id.item_location_detail_tv);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.areaTextView.setText(data.get(i).getCityName() + data.get(i).getAdName());
        viewHolder.detailTextView.setText(data.get(i).toString());
        return view;
    }

    public static class ViewHolder {
        TextView areaTextView;
        TextView detailTextView;

    }
}
